package com.ruoyi.statistics.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.statistics.service.IGoodAnalyseService;

/**
 * 商品数据分析Controller
 * 
 * @author ruoyi
 * @date 2025-01-18
 */
@RestController
@RequestMapping("/statistics/good")
public class GoodAnalyseController extends BaseController
{
    @Autowired
    private IGoodAnalyseService goodAnalyseService;

    /**
     * 获取销量趋势数据（折线图）
     */
    @GetMapping("/trend")
    public AjaxResult getSalesTrend(
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(defaultValue = "day") String timeType)
    {
        Long orgId = getOrgId();
        List<Map<String, Object>> data = goodAnalyseService.getSalesTrend(orgId, startDate, endDate, timeType);
        return AjaxResult.success(data);
    }

    /**
     * 获取品类结构数据（环形饼图）
     */
    @GetMapping("/category")
    public AjaxResult getCategoryStructure(
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate)
    {
        Long orgId = getOrgId();
        List<Map<String, Object>> data = goodAnalyseService.getCategoryStructure(orgId, startDate, endDate);
        return AjaxResult.success(data);
    }

    /**
     * 获取SKU矩阵数据（气泡图）
     */
    @GetMapping("/matrix")
    public AjaxResult getSkuMatrix(
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate)
    {
        Long orgId = getOrgId();
        List<Map<String, Object>> data = goodAnalyseService.getSkuMatrix(orgId, startDate, endDate);
        return AjaxResult.success(data);
    }

    /**
     * 获取综合统计数据
     */
    @GetMapping("/summary")
    public AjaxResult getSummaryData(
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate)
    {
        Long orgId = getOrgId();
        Map<String, Object> data = goodAnalyseService.getSummaryData(orgId, startDate, endDate);
        return AjaxResult.success(data);
    }
}